package com.jk.controller;

import com.jk.entity.BankCard;
import com.jk.entity.Payment;
import com.jk.entity.User;
import com.jk.service.PaymentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("payment")
public class PaymentController {
    @Autowired
    private PaymentService paymentService;
    /**
     * 查询余额数据
     * @param request
     * @return
     */
    @GetMapping("queryPayment")
    public Payment queryPayment(HttpServletRequest request){
        /**登录成功后获取session里面的用户信息*/
        User user =(User) request.getSession().getAttribute("login");
        /**查询出用户账户*/
        /*String userId= user.getUserId();*/
        String userId = "446c965408ed4d1cbbe32157f9bd2f32";
        //去后台查询总条数和所有数据
        Payment dbpayment = paymentService.queryPayment(userId);
        return dbpayment;
    }

    /**
     * 充值  从余额充值到余额宝（）
     * @return
     */
    @PostMapping("updateYuebao")
    public boolean updateYuebao(HttpServletRequest request, double paymentInto, String payPass){
        User payment = (User) request.getSession().getAttribute("login");
        /*String userId = payment.getUserId();
        String payPassword = payment.getPayPassword();*/
        String userId = "446c965408ed4d1cbbe32157f9bd2f32";
        String payPassword = "666666";
        if(payPass != null && !"".equals(payPass) && payPassword.equals(payPass)){
            return paymentService.updatePayment(userId,paymentInto);
        }else{
            return false;
        }
    }
    /**
     * 充值  从银行卡充值至余额（）
     * @return
     */
    @PostMapping("updateBankYue")
    public boolean updateBankYue(HttpServletRequest request, double paymentInto, String payPass){
        User payment = (User) request.getSession().getAttribute("login");
        /*String userId = payment.getUserId();
        String payPassword = payment.getPayPassword();*/
        String userId = "446c965408ed4d1cbbe32157f9bd2f32";String payPassword = "666666";
        if(payPass != null && !"".equals(payPass) && payPassword.equals(payPass)){
            return paymentService.updateBankYue(userId,paymentInto);
        }else{
            return false;
        }
    }

    /**
     * 新增数据
     * @param payment
     */
    @PostMapping("addPayment")
    public void addPayment(Payment payment){

        paymentService.addPayment(payment);
    }

    /**
     * 删除数据
     * @param accountId
     */
    @GetMapping("deletePayment")
    public void deletePayment(String accountId){
        paymentService.deletePayment(accountId);
    }

    /**
     * 提现
     * @param request
     * @param paymentInto
     * @return
     */
    @PutMapping("updateZhuanchu")
    public boolean updateZhuanchu(HttpServletRequest request, double paymentInto, String payPass){
        User payment = (User) request.getSession().getAttribute("login");
       /* String userId = payment.getUserId();
        String payPassword = payment.getPayPassword();*/
        String userId = "446c965408ed4d1cbbe32157f9bd2f32";
        String payPassword = "666666";
        if(payPass != null && !"".equals(payPass) && payPassword.equals(payPass)){
            return paymentService.updateTiXian(userId,paymentInto);
        }else{
            return false;
        }
    }
    /**
     * 查询银行卡号
     * @param
     * @return
     */
    @GetMapping("queryBankId")
    public BankCard queryBankId(HttpServletRequest request){
        /**登录成功后获取session里面的用户信息*/
        //User user =(User) request.getSession().getAttribute("login");
        /**查询出用户账户*/
        /*String userId= user.getUserId();*/
        String userId = "446c965408ed4d1cbbe32157f9bd2f32";
        //去后台查询总条数和所有数据
        BankCard bankCard = paymentService.queryBankId(userId);
        return bankCard;
    }
    /**
     * 查询手机号码
     * @param
     * @return
     */
   /* @GetMapping("queryPhoneNumber")
    public User queryPhoneNumber(HttpServletRequest request){
        *//**登录成功后获取session里面的用户信息*//*
        //User user =(User) request.getSession().getAttribute("login");
        *//**查询出用户账户*//*
        *//*String userId= user.getUserId();*//*
        String userId = "446c965408ed4d1cbbe32157f9bd2f32";
        //去后台查询总条数和所有数据
        User userPhoneNumber = paymentService.queryPhoneNumber(userId);
        return userPhoneNumber;
    }*/
}
